/**
* @Author: Gosin
* @Date: 2019/12/12 15:40
 */
package service

import (
	"context"
	"git.900sui.cn/kc/rpcPay/common/logics"
	"git.900sui.cn/kc/rpcPay/common/logics/fund"
	"git.900sui.cn/kc/rpcPay/common/logics/fundAgent"
	"git.900sui.cn/kc/rpcinterface/interface/pay"
)

type Pay struct {
}

//二维码支付
func (p *Pay) PayQr(ctx context.Context, args *pay.PayInfo, reply *string) (err error) {
	*reply, err = new(logics.PayLogic).PayQr(args)
	return err
}

//H5在线支付
func (p *Pay) PayH5(ctx context.Context, args *pay.PayInfo, reply *string) (err error) {
	*reply, err = new(logics.PayLogic).PayH5(args)
	return err
}

//H5新版在线支付
func (p *Pay) PayH5New(ctx context.Context, args *pay.PayInfo, reply *pay.PayH5) (err error) {
	res, err := new(logics.PayLogic).PayH5New(args)
	if err != nil {
		return err
	}
	*reply = *res
	return nil
}

//微信小程序支付
func (p *Pay) PayWxapp(ctx context.Context, args *pay.PayInfo, reply *string) error {
	res, err := new(logics.PayLogic).PayWxApp(args)
	if err != nil {
		return err
	}
	*reply = res.String()
	return err
}

//微信公众号支付
func (p *Pay) PayWxOfficial(ctx context.Context, args *pay.PayInfo, reply *string) error {
	res, err := new(logics.PayLogic).PayWxOfficial(args)
	if err != nil {
		return err
	}
	*reply = res.String()
	return err
}

//App支付（微信/支付宝）
func (p *Pay) PayApp(ctx context.Context, args *pay.PayInfo, reply *string) error {
	res, err := new(logics.PayLogic).PayApp(args)
	if err != nil {
		return err
	}
	*reply = res.String()
	return err
}

func (p *Pay) PayAppSign(ctx context.Context, args *pay.PayInfo, reply *string) error {
	res, err := new(logics.PayLogic).PayAppSign(args)
	if err != nil {
		return err
	}
	*reply = res
	return err
}

//回调通知
func (p *Pay) Notify(ctx context.Context, args *pay.ArgsNotify, reply *bool) error {
	err := new(logics.PayLogic).Notify(ctx, args)
	if err != nil {
		return err
	}
	*reply = true
	return nil
}

//异步回调响应
func (p *Pay) NotifyResponse(ctx context.Context, args *pay.ArgsNotify, reply *pay.ReplyNotifyResponse) (err error) {
	str, err := new(logics.PayLogic).NotifyResponse(ctx, args)
	reply.ResponseJsonStr = str
	if err != nil {
		return err
	}
	return nil
}

func (p *Pay) PayInfo(ctx context.Context, orderSn *string, reply *pay.PayNotify) error {
	res, err := new(logics.PayLogic).PayInfo(*orderSn)
	if err != nil {
		return err
	}
	*reply = *res
	return nil
}

func (p *Pay) PayAgent(ctx context.Context, orderSn *string, reply *bool) error {
	if err := new(logics.PayLogic).PayAgent(ctx, *orderSn); err != nil {
		return err
	}
	*reply = true
	return nil
}

/**
 * 资金清分【商家】
 * @return void
 */
func (p *Pay) AngelChannel(ctx context.Context, timeUnix *int, reply *bool) error {
	if err := new(logics.PayLogic).AngelChannel(); err != nil {
		return err
	}
	*reply = true
	return nil
}

/**
 * 资金清分【平台】
 * @return void
 */
func (p *Pay) AngelChannelPlat(ctx context.Context, timeUnix *int, reply *bool) error {
	if err := new(logics.PayLogic).AngelChannelPlat(); err != nil {
		return err
	}
	*reply = true
	return nil
}

/**
 * 资金清分【保险-正常】
 * @return void
 */
func (p *Pay) AngelChannelInsure(ctx context.Context, timeUnix *int, reply *bool) error {
	if err := new(logics.PayLogic).AngelChannelInsure(); err != nil {
		return err
	}
	*reply = true
	return nil
}

/**
 * 资金清分【保险-续保】
 * @return void
 */
func (p *Pay) AngelChannelRenewInsure(ctx context.Context, timeUnix *int, reply *bool) error {
	if err := new(logics.PayLogic).AngelChannelRenewInsure(); err != nil {
		return err
	}
	*reply = true
	return nil
}

func (p *Pay) CcbAgent(ctx context.Context, timeUnix *int, reply *bool) error {
	new(fundAgent.CcbFundAgentLogic).Agent(ctx)
	return nil
}

func (p *Pay) CcbAgentFund(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.CcbFundAgentLogic).AgentFund(ctx)
	return nil
}

/**
 * 正常执行杉德代付【商家资金】
 * @return void
 */
func (p *Pay) SandAgent(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).Agent(ctx)
	return nil
}

/**
 * 查询杉德代付结果【商家资金】
 * @return void
 */
func (p *Pay) SandAgentFund(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentFund(ctx)
	return nil
}

/**
 * 正常执行杉德代付【平台】
 * @return void
 */
func (p *Pay) SandAgentPlat(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentPlat(ctx)
	return nil
}

/**
 * 查询杉德代付结果【平台】
 * @return void
 */
func (p *Pay) SandAgentFundPlat(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentFundPlat(ctx)
	return nil
}

/**
 * 正常执行杉德代付【保险公司正常出单保费资金】
 * @return void
 */
func (p *Pay) SandAgentInsure(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentInsure(ctx)
	return nil
}

/**
 * 查询杉德代付结果【保险公司正常出单保费资金】
 * @return void
 */
func (p *Pay) SandAgentFundInsure(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentFundInsure(ctx)
	return nil
}

/**
 * 正常执行杉德代付【保险公司续保出单保费资金】
 * @return void
 */
func (p *Pay) SandAgentRenewInsure(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentRenewInsure(ctx)
	return nil
}

/**
 * 查询杉德代付结果【保险公司续保出单保费资金】
 * @return void
 */
func (p *Pay) SandAgentFundRenewInsure(ctx context.Context, timeUnix *int, reply *bool) error {
	*reply = new(fundAgent.SandFundAgentLogic).AgentFundRenewInsure(ctx)
	return nil
}

/**
 * 正常执行杉德代付【共享卡】
 * @return void
 */
func (p *Pay) SandAgentShareCard(ctx context.Context, timeUnix *int, reply *bool) (err error) {
	*reply = new(fundAgent.SandFundAgentLogic).AgentShareCard(ctx)
	return
}

/**
 * 查询杉德代付结果【共享卡】
 * @return void
 */
func (p *Pay) SandAgentFundShareCard(ctx context.Context, timeUnix *int, reply *bool) (err error) {
	*reply = new(fundAgent.SandFundAgentLogic).AgentFundShareCard(ctx)
	return
}

//根据订单号，获取代付状态信息
func (p *Pay) GetAgentInfoByOrderSn(ctx context.Context, orderSn *string, reply *pay.ReplyGetAgentInfoByOrderSn) (err error) {
	*reply, err = new(fund.PlatformFundLogic).GetAgentInfoByOrderSn(orderSn)
	return err
}

//根据clearId，获取代付状态信息
func (p *Pay) GetAgentInfoByClearid(ctx context.Context, clearId *int, reply *pay.ReplyGetAgentInfoByOrderSn) (err error) {
	*reply, err = new(fund.PlatformFundLogic).GetAgentInfoByClearid(clearId)
	return err
}
